package com.aceitunaproject.server.permissions;

import com.aceitunaproject.server.AceitunaContext;
import com.aceitunaproject.server.player.Player;
import com.aceitunaproject.shared.exceptions.gamerules.EnumIllegalAction;
import com.aceitunaproject.shared.exceptions.gamerules.PermissionDeniedException;
import com.aceitunaproject.shared.playerdata.PlayerData;

/**
 * @author Federico Bergstein
 * 
 *         Default implementation of Permission Manager
 */
public class PermissionManagerImpl implements PermissionManager {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.aceitunaproject.server.permissions.PermissionManager#canMoveUnit(
	 * long, int, int, com.aceitunaproject.server.player.Player)
	 */
	@Override
	public void canMoveUnit(long unitID, int destinationX, int destinationY,
			Player player) throws PermissionDeniedException {
		// TODO: Semi-stub, for now does not allow movement if the tile is
		// already occupied by an
		// unit not under the player's control
		for (Long id : AceitunaContext.getMapManager().getTile(destinationX,
				destinationY).getUnitIDs()) {
			if (!AceitunaContext.getUnitManager().getUnit(id).getController()
					.equals(player)) {
				PlayerData playerData = new PlayerData();
				playerData.setName(AceitunaContext.getUnitManager().getUnit(id)
						.getController().getName());
				throw new PermissionDeniedException(
						EnumIllegalAction.MOVE_TILE_OCCUPIED_BY_OTHER_PLAYER,
						playerData);

			}
		}

	}

	@Override
	public void canBuildSettlement(long unitID, int x, int y, Player player)
			throws PermissionDeniedException {
		// TODO: stub

	}
	
	@Override
	public void canBuildInstallation(long unitID,String installationType, int x, int y, Player player)
			throws PermissionDeniedException {
		// TODO: stub

	}

	@Override
	public void canRecruitUnit(long settlementId, int persons, Player player)
			throws PermissionDeniedException {
		// TODO Auto-generated method stub
		
	}
}
